package com.gh.strategy.impl;

import com.gh.anno.Strategy;
import com.gh.exception.FruitException;
import com.gh.strategy.ProductStrategy;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;


/**
 * @author heyu
 * @date 2022:11:06 10:00
 * FruitDiscount 打折
 */
@Strategy("FruitDiscount")
@Component
public class ProductStrategyFruitDiscount implements ProductStrategy {
    @Override
    public BigDecimal calProductPrice(double price, Integer num, double discount) {

        BigDecimal  bigDecimal = (num >= 0&&discount>=0&&discount<=10&&price>=0)?BigDecimal.valueOf(price * num * discount/10):null;

        if (bigDecimal==null) {
            throw new FruitException("参数有问题，请重新输入");
        }else {
            return bigDecimal;
        }

    }


}
